//----------------------------------------------------------------------------
// View 'HerhaalReceptDetails'
//----------------------------------------------------------------------------

var viewHerhaalReceptDetails = Ti.UI.createScrollView({
   contentWidth : 'auto',
   contentHeight : 'auto',
   showVerticalScrollIndicator : true,
   showHorizontalScrollIndicator : true
});

var viewLetterhead1 = Titanium.UI.createImageView({
   top : '0',
   left : '10',
   height : '50',
   width : '75',
   image : 'images/logo/Letterhead1.png'
});
var viewLetterhead2 = Titanium.UI.createImageView({
   top : '0',
   right : '0',
   height : '100',
   width : '180',
   image : 'images/logo/Letterhead2.png'
});

var viewHerhaalReceptDetailsContent = Titanium.UI.createImageView();

//----- Buttons
var btnTerugNaarHistorie = Titanium.UI.createButton({
   title : T_CLOSE
});
btnTerugNaarHistorie.addEventListener('click', terugNaarHistorie);



//----- Functions
function getHHRecept(dt) {
   viewHerhaalReceptDetailsContent = Titanium.UI.createView({
      top : '10',
      borderRadius : '3',
      borderColor : middenblauw,
      backgroundColor : wit
   });
   if (isIphone()) {
      viewHerhaalReceptDetailsContent.setWidth('90%');
   }
   else if (isIpad()) {
      viewHerhaalReceptDetailsContent.setWidth('500');
   }

   hhreceptendb = Ti.Database.open('hhrecepten');
   var hhreceptRS = hhreceptendb.execute('SELECT * FROM hhrecepten WHERE date_time=?', dt);

   if (hhreceptRS.isValidRow()) {
      
      var hhreceptDetails = hhreceptRS.getFieldByName('initials') + ' ' + 
         hhreceptRS.getFieldByName('name') + '\n' +
         hhreceptRS.getFieldByName('bdate') + '\n' +
         hhreceptRS.getFieldByName('street') + '\n' +
         hhreceptRS.getFieldByName('postcode') + ' ' + hhreceptRS.getFieldByName('place') + '\n' +
         hhreceptRS.getFieldByName('phone') + '\n\n' +
         'Medicijn : ' + hhreceptRS.getFieldByName('medicine') + '\n' +
         'Dosering : ' + hhreceptRS.getFieldByName('dose') + '\n' +
         'Aantal : ' + hhreceptRS.getFieldByName('number') + '\n' +
         'Gebruik : ' + hhreceptRS.getFieldByName('usage') + '\n\n' +
         'Apotheek : ' + hhreceptRS.getFieldByName('pharmacy');
      
      viewHerhaalReceptDetailsContent.add(Ti.UI.createLabel({
         top : '60',
         left : '10',
         color : middenblauw,
         textAlign : Ti.UI.TEXTALIGNMENTLEFT,
         font : {
            fontSize : 12,
            fontFamily : customFont
         },
         text : hhreceptDetails
      }));

      viewHerhaalReceptDetailsContent.add(Ti.UI.createImageView({
         top : '255',
         image : hhreceptRS.getFieldByName('image')
      }));

      viewHerhaalReceptDetailsContent.add(viewLetterhead1, viewLetterhead2);
      viewHerhaalReceptDetails.add(viewHerhaalReceptDetailsContent);
   }
   hhreceptRS.close();
   hhreceptendb.close();
}

function terugNaarHistorie() {
   viewHerhaalReceptDetails.remove(viewHerhaalReceptDetailsContent);
   viewHerhaalReceptDetailsContent = null;
   //
   winHHRecept.remove(viewHerhaalReceptDetails);
   winHHRecept.add(viewHistorie);
   winHHRecept.leftNavButton = btnTerug;
   winHHRecept.rightNavButton = btnHistorieWissen;
   winHHRecept.setTitle('Herhaalrecepten');
}
